package com.jzl.swing.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.jzl.swing.dao.UserDao;
import com.jzl.swing.entity.User;
import com.jzl.swing.object.jactory.ObjectFactory;
import com.jzl.swing.service.UserService;
import com.jzl.swing.util.Util;

public class UserServiceImpl implements UserService{
	private UserDao userDao = (UserDao) ObjectFactory.getInstance("UserDao");
	

	@Override
	public boolean register(User user) throws Exception {
		if (Util.isEmpty(user.getUser_name())) {
			return false;
		}
		if(Util.isEmpty(user.getUser_pass())) {
			return false;
		}
		if(Util.isEmpty(user.getUser_iden())) {
			return false;
		}
		userDao.add(user);
		return true;
	}

	@Override
	public boolean login(User user) throws Exception {
		List<User> userList = new ArrayList<User>();
		userList = userDao.queryAll();
		if (userList==null) {
			return false;
		}
		for (User user2 : userList) {
			if (user.getUser_name().equals(user2.getUser_name()) && user.getUser_pass().equals(user2.getUser_pass()) && user.getUser_iden().equals(user2.getUser_iden())) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void cancel(User user) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<User> queryUserAll() throws Exception {
		// TODO Auto-generated method stub
		return userDao.queryAll();
	}

	@Override
	public User queryUser(User user) throws Exception {
		return userDao.queryByName(user.getUser_name());
	}

	@Override
	public int insertUser(User user) throws Exception {
		return userDao.add(user);
	}

	@Override
	public int deleteUser(User user) throws Exception {
		return userDao.delete(user);
	}

	@Override
	public int modifyUser(User user) throws Exception {
		return userDao.modify(user);
	}
}
